<template>
  <div class="container">
    <div>
      <view class="section tc">
        <video
          id="myVideo"
          src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400"
          enable-danmu
          danmu-btn
          controls
        ></video>
        <view class="btn-area">
          <button>云消息操作视频教程</button>
        </view>
      </view>

    </div>
  </div>
</template>
<script>
import { requestPost } from '@/utils/index'
export default {
  data () {
    return {
      userInfo: {},
      code: '',
      jtq: '',
      enen: 0
    }
  },
  onLoad () {
    wx.setNavigationBarTitle({
      title: ''
    })
    this.showuserinfo()
  },
  onUnload () {
    clearInterval(this.jtq)
  },
  methods: {
    showuserinfo () {
      var that = this
      this.jtq = setInterval(function () {
        if (this.enen === 1) {
          return
        }
        wx.getUserInfo({
          success: (res) => {
            that.userInfo = res.userInfo
            wx.setStorageSync('headimg', that.userInfo.avatarUrl)
            wx.setStorageSync('city', that.userInfo.city)
            this.enen = 1
          }
        })
      }, 1000)
    },
    getUserInfo () {
      var that = this
      wx.login({
        success: (res) => {
          that.code = res.code
          that.getOpenid()
        }
      })
    },
    saveUserInfo () {
      var data = {
        'avatarurl': this.userInfo.avatarUrl,
        'city': this.userInfo.city,
        'country': this.userInfo.country,
        'gender': this.userInfo.gender,
        'language': this.userInfo.language,
        'nickname': this.userInfo.nickName,
        'province': this.userInfo.province,
        'openid': wx.getStorageSync('openid')
      }
      var url = wx.getStorageSync('requestUrl') + '/harduser/xcxlogin'
      requestPost(url, data, 'POST').then(function (value) {
        wx.redirectTo({
          url: '/pages/counter/main'
        })
        console.log('登录成功')
      }, function (value) {
        console.log('登录错误')
      })
    },
    getOpenid () {
      var data = {
        'obj': {'js_code': this.code}
      }
      var url = wx.getStorageSync('requestUrl') + '/api/wxGetOpenid'
      requestPost(url, data, 'POST').then(function (value) {
        wx.setStorageSync('openid', value.openid)
        // console.log('openid success' + wx.getStorageSync('openid'))
      }, function (value) {
        console.log('获取错误')
      })
    },
    gopage () {
      this.saveUserInfo()
    }
  }
}
</script>
<style scoped>
.container{
  background-size: contain;
  width: 100%;
  height: 680px;
  text-align: left;
  background-repeat: no-repeat;
  background-position-y: 200px;
  background-size: 400px;
}
</style>
